import Vue from 'vue';
import VueRouter from 'vue-router';
import {TITLE, LAYOUT_PATH} from '@/config/setting';
// import HomeView from '../views/LogView.vue';

Vue.use(VueRouter);

const routes = [
	// {
	// 	path: '/',
	// 	name: 'home',
	// 	component: HomeView, // 与根路径关联的组件
	// },
	{
		path: '/about',
		name: 'about',
		// route level code-splitting
		// this generates a separate chunk (about.[hash].js) for this route
		// which is lazy-loaded when the route is visited.
		component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue'),
	},
	{
		path: '/user',
		name: 'user',
		meta: {title: '用户列表'},
		component: () => import('../views/UserView.vue'),
	},
	{
		path: '/shop',
		name: 'shop',
		meta: {title: '门店列表'},
		component: () => import('../views/ShopView.vue'),
	},
	{
		path: '/log',
		name: 'log',
		meta: {title: '日志列表'},
		component: () => import('../views/LogView.vue'),
	},
	{
		path: '/product',
		name: 'product',
		meta: {title: '可预约商品'},
		component: () => import('../views/ProductView.vue'),
	},
];

const router = new VueRouter({
	mode: 'history',
	routes,
});

router.beforeEach((to, from, next) => {
	//beforeEach是router的钩子函数，在进入路由前执行
	if (to.meta.title) {
		//判断是否有标题
		document.title = TITLE + '-' + to.meta.title;
	}
	if (to.path == '/') {
		next({
			path: LAYOUT_PATH,
		});
	} else {
		next(); //执行进入路由，如果不写就不会进入目标页
	}
});

export default router;
